<script setup lang="ts">
import { check } from '@tauri-apps/plugin-updater';
import { onMounted } from 'vue';

import router from '@/app-router';

onMounted(checkUpdate);

async function checkUpdate(): Promise<void> {
  let updateAvailable = false;

  // If has internet connectivity then we need to check available update.
  if (navigator.onLine) {
    try {
      const update = await check();
      updateAvailable = update?.rid != null;
    } catch {
      // Even with internet connectivity network access still might be not available.
      // We need to ignore such issue and continue.
    }
  }

  if (updateAvailable) {
    router.replace('/app-updater');
  } else {
    router.replace('/home');
  }
}
</script>

<template>
  <div class="main-container">
    <img src="/tauri.svg" />
  </div>
</template>

<style scoped>
.main-container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

img {
  width: 60px;
}
</style>
